package bite20220403;

import com.sun.scenario.animation.shared.AnimationAccessor;

class Animal{
    private String name;
    private int age;

    public Animal() {
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void eat(){
        System.out.println(this.name+"eating");
    }
}

class Cat extends Animal{
    //当子类继承父类的时候，一定要先创建父类再创建子类
    //当构造子类的时候，一定要先帮助父类构造
    private String hair;


    public Cat(){
        super("cat",12);//继承父类
        //先有父，再有子
        this.hair = "black";
    }
    public void mew(){
        System.out.println(this.getName());//子类无法访问父类的私有变量
    }
}


public class Test {

    public static void main(String[] args) {
        Animal animal = new Cat();//父类引用，引用子类对象
    }
    public static void main1(String[] args) {
        Cat cat = new Cat();
        cat.mew();
        cat.eat();

        Animal animal = new Animal();
        animal.eat();
    }
}
